import 'package:flutter/material.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/routers/fluro_navigator.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/widgets/load_image.dart';
import 'package:flutter_deer/widgets/my_app_bar.dart';
import 'package:flutter_deer/widgets/my_button.dart';
import 'package:intl/intl.dart';
import 'package:timer_count_down/timer_count_down.dart';
import 'package:flutter_gen/gen_l10n/deer_localizations.dart';

class WithdrawalResultPage extends StatefulWidget {

  const WithdrawalResultPage({super.key,this.type});

  final int? type;

  @override
  _WithdrawalResultPageState createState() => _WithdrawalResultPageState();
}

class _WithdrawalResultPageState extends State<WithdrawalResultPage> {

  @override
  Widget build(BuildContext context) {
    String formattedTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());
    return Scaffold(
      appBar: MyAppBar(
        title: '${DeerLocalizations.of(context)!.withdrawalResults.nullSafe}',
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: <Widget>[
            Gaps.vGap50,
            LoadAssetImage(widget.type==2?'account/sqsb':'account/sqcg',
              width: 80.0,
              height: 80.0,
            ),
            Gaps.vGap12,
            Text(
              widget.type==2?'${DeerLocalizations.of(context)!.withdrawApplyFail.nullSafe}':'${DeerLocalizations.of(context)!.withdrawApplySuccess.nullSafe}',
              style: TextStyles.textSize16,
            ),
            Gaps.vGap8,
            Text(
              formattedTime,
              style: Theme.of(context).textTheme.titleSmall,
            ),
            Gaps.vGap8,
            Countdown(
              seconds: 5,
              build: (BuildContext context, double time) => Text(time.toString()+'${DeerLocalizations.of(context)!.second.nullSafe}${DeerLocalizations.of(context)!.after.nullSafe}${DeerLocalizations.of(context)!.returnWithdrawalPage.nullSafe}',style: Theme.of(context).textTheme.titleSmall),
              interval: Duration(milliseconds: 1000),
              onFinished: () {
                NavigatorUtils.goBackWithParams(context, 'success');
              },
            ),
            Gaps.vGap24,
            MyButton(
              onPressed: () {
                if(widget.type==1) {
                  NavigatorUtils.goBackWithParams(context, 'success');
                }else {
                  NavigatorUtils.goBack(context);
                }
              },
              text: '${DeerLocalizations.of(context)!.back.nullSafe}',
            )
          ],
        ),
      ),
    );
  }
}
